package exception_;

import com.sun.org.apache.bcel.internal.generic.NEW;

/**
 * @Author 小闽
 * @Date 2024/9/23 14:46
 * @PackageName: exception_
 * @ClassName: TryCatchDetail02
 * @Description: 异常处理细节
 * @Version 1.0
 */
public class TryCatchDetail02 {
    public static void main(String[] args) {
        // 1. 可以有多个catch语句，捕获不同的异常，进行不同的业务处理。
        // 2. 要求父类异常在后，子类异常在前
        try {
            Person01 person01 = new Person01();
            int num1 = 10;
            int num2 = 0;
            int res = num1/num2;
            person01 = null;
            System.out.println(person01.getName()); // 空指针异常 NullPointerException
        } catch (NullPointerException e) {
            System.out.println("空指针异常=" + e.getMessage());
        }catch (ArithmeticException e){
            System.out.println("算术运算异常=" + e.getMessage());
        }catch (Exception e){
            System.out.println("其他异常=" + e.getMessage());
        }finally {
            System.out.println("关闭连接，释放资源...");
        }
    }
}

class Person01{
    public String name = "jack";
//    public void test(){
//
//    }

    public String getName() {
        return name;
    }
}
